import { getStore } from '@/util/store'
// import { dateFormat } from '@/util/date'

const dic = {
  applyType: [
    {
      label: '潜在供应商升为临时供应商',
      value: '0'
    },
    {
      label: '原合格供方新供物料分类',
      value: '1'
    },
    {
      label: '原临时供方新供物料分类',
      value: '2'
    }
    // {
    //   label: '临时供应商延期',
    //   value: '3'
    // }
  ],
  materialType: [
    {
      label: '物料分类1',
      value: '0'
    },
    {
      label: '物料分类2',
      value: '1'
    }
  ],
  factory: [
    {
      label: '工厂1',
      value: '0'
    },
    {
      label: '工厂2',
      value: '1'
    },
    {
      label: '工厂3',
      value: '2'
    },
    {
      label: '工厂4',
      value: '3'
    }
  ],
  proposedSupplyMaterialType: [
    {
      label: '自制产品原辅材料或成品/半成品',
      value: '1'
    },
    {
      label: '大零售全外购成品',
      value: '2'
    },
    {
      label: '机物料',
      value: '3'
    },
    {
      label: '委外加工',
      value: '4'
    }
  ],
  applyReason: [
    {
      label: '自然灾害下所采取的应急措施，保障供应',
      value: '1'
    },
    {
      label: '原合格供方不能满足采购需求，在订单紧急情况下开发临供',
      value: '2'
    },
    {
      label: '客户或销售急需并认可的物料',
      value: '3'
    },
    {
      label: '其他',
      value: '4'
    }
  ],
  isPlan: [
    {
      label: '是',
      value: '1'
    },
    {
      label: '否',
      value: '2'
    }
  ]
}

export const option = function () {
  return {
    labelWidth: 160,
    emptyBtn: false,
    submitBtn: false,
    detail: ['view'].includes(this.type),
    column: [
      {
        label: '申请编号',
        span: 8,
        prop: 'applyCode',
        maxlength: 100,
        disabled: true
      },
      {
        label: '申请人',
        span: 8,
        prop: 'applicant',
        maxlength: 100,
        disabled: true,
        value: getStore({ name: 'userInfo' }).user_name
      },
      {
        label: '申请时间',
        span: 8,
        prop: 'applyDate',
        type: 'date',
        format: 'yyyy-MM-dd',
        valueFormat: 'yyyy-MM-dd',
        disabled: true,
        value: new Date()
      },
      {
        label: '申请类型',
        prop: 'applyType',
        type: 'select',
        dicData: dic.applyType,
        props: {
          label: 'label',
          value: 'value'
        },
        span: 8,
        rules: [
          {
            required: true,
            message: '请选择申请类型',
            trigger: 'change'
          }
        ]
      },
      {
        label: '供应商名称',
        span: 8,
        prop: 'supplierName',
        maxlength: 50,
        formslot: true,
        rules: [
          {
            required: true,
            message: '请输入供应商名称',
            trigger: 'change'
          }
        ]
      },
      {
        label: '工厂',
        prop: 'factory',
        type: 'select',
        dicData: dic.factory,
        props: {
          label: 'label',
          value: 'value'
        },
        span: 8,
        multiple: true,
        rules: [
          {
            required: true,
            message: '请选择工厂',
            trigger: 'change'
          }
        ]
      },
      {
        label: '物料分类',
        prop: 'materialType',
        type: 'select',
        span: 8,
        dicData: dic.materialType,
        props: {
          label: 'label',
          value: 'value'
        },
        multiple: true,
        rules: [
          {
            required: true,
            message: '请选择物料分类',
            trigger: 'change'
          }
        ]
      },
      {
        label: '拟供物料类别',
        prop: 'proposedSupplyMaterialType',
        type: 'select',
        span: 8,
        dicData: dic.proposedSupplyMaterialType,
        props: {
          label: 'label',
          value: 'value'
        }
      },
      {
        label: '拟供物料名称',
        prop: 'proposedSupplyMaterialName',
        span: 8,
        maxlength: 100,
        rules: [
          {
            required: true,
            message: '请输入拟供物料名称',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '拟供物料年用量(万元)',
        prop: 'proposedSupplyMaterialNum',
        type: 'number',
        controls: false,
        span: 8,
        precision: 2
      },
      {
        label: '有效期起',
        prop: 'termValidityStart',
        type: 'date',
        pickerOptions: {
          disabledDate: data => data.getTime() < new Date(this.form.termValidityEnd).getTime()
        },
        span: 8,
        rules: [
          {
            required: true,
            message: '请选择有效期起',
            trigger: 'change'
          }
        ]
      },
      {
        label: '有效期止',
        prop: 'termValidityEnd',
        type: 'date',
        pickerOptions: {
          disabledDate: data => data.getTime() < new Date(this.form.termValidityStart).getTime()
        },
        span: 8,
        rules: [
          {
            required: true,
            message: '请选择有效期止',
            trigger: 'change'
          }
        ]
      },
      {
        label: '申请原因',
        prop: 'applyReason',
        type: 'select',
        dicData: dic.applyReason,
        props: {
          label: 'label',
          value: 'value'
        },
        span: 8,
        multiple: true,
        rules: [
          {
            required: true,
            message: '请选择申请原因',
            trigger: 'change'
          }
        ]
      },
      {
        label: '原因说明',
        prop: 'alterationExplain',
        type: 'textarea',
        minRows: 4,
        maxRows: 5,
        maxlength: 500,
        span: 24
      },
      {
        label: '是否有合格导入计划',
        prop: 'isPlan',
        type: 'select',
        span: 8,
        dicData: dic.isPlan,
        props: {
          label: 'label',
          value: 'value'
        },
        rules: [
          {
            required: true,
            message: '请选择申请原因',
            trigger: 'change'
          }
        ],
        value: '1',
        control: (val, form) => {
          if (val === '2') {
            return {
              planImportTime: {
                display: false
              }
            }
          } else if (val === '1') {
            return {
              planImportTime: {
                display: true
              }
            }
          }
        }
      },
      {
        label: '计划导入时间',
        prop: 'planImportTime',
        span: 8,
        type: 'date',
        pickerOptions: {
          disabledDate: data => data.getTime() < new Date().getTime()
        },
        rules: [
          {
            required: true,
            message: '请选择计划导入时间',
            trigger: 'change'
          }
        ]
      },
    ]
  }
}

export const supplierOption = [
  { label: '选择', prop: 'radio', width: 50 },
  { label: '供应商编码', prop: 'supplierCode' },
  { label: '供应商名称', prop: 'supplierName' },
  { label: '联系人', prop: 'contact' },
  { label: '移动电话', prop: 'phone' },
  { label: '邮箱', prop: 'email' }
]
